import cPickle
import sys
import matplotlib.pyplot as mp

mp.ion()
image_rgb = None
image_depth = None

def mapIndex(lenA, lenB, idx):
    ratio = float(lenA)/lenB
    return int(round(ratio*idx))
    

dfile = open(sys.argv[1]+'_depth.data')
ifile = open(sys.argv[1]+'_image.data')

print "Loading data..."
depthDataArray = cPickle.load(dfile)
rgbDataArray = cPickle.load(ifile)
print "Done!"

#print "depthData length: ",len(depthDataArray)
#print "rgbData length: ",len(rgbDataArray)

for i in range(0,len(depthDataArray)):
    depthData =  depthDataArray[i]
    rgbData = rgbDataArray[mapIndex(len(rgbDataArray),len(depthDataArray),i)]
    
    mp.figure(1)
    if image_depth:
        image_depth.set_data(depthData)
    else:
        image_depth = mp.imshow(depthData, interpolation='nearest', animated=True)
    mp.draw()

    mp.figure(2)
    if image_rgb:
        image_rgb.set_data(rgbData)
    else:
        image_rgb = mp.imshow(rgbData, interpolation='nearest', animated=True)
    mp.draw()


